package com.aabte.hystrixlearn.hystrix.command;

import com.aabte.hystrixlearn.common.HttpClientUtil;
import com.aabte.hystrixlearn.model.ProductInfo;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import lombok.extern.slf4j.Slf4j;

/**
 * 普通
 *
 * @author Daniel
 */
@Slf4j
public class GetProductInfoCommand extends HystrixCommand<ProductInfo> {

    private final Long productId;

    public GetProductInfoCommand(Long productId) {
        super(HystrixCommandGroupKey.Factory.asKey("GetProductInfoCommand"));
        this.productId = productId;
    }

    @Override
    protected ProductInfo run() throws Exception {
        log.info("Start run. productId: {}", productId);
        String url = "http://127.0.0.1:8080/product/" + this.productId;
        ProductInfo productInfo = HttpClientUtil.getInstance().getForObject(url, ProductInfo.class);
        log.info("End run. productInfo: {}", productInfo);
        return productInfo;
    }
}
